//
//  RecordView.m
//  TestChat
//
//  Created by yull on 14/12/7.
//  Copyright (c) 2014年 yull. All rights reserved.
//

#import "RecordView.h"

@interface RecordView ()

@property (nonatomic, strong) UIView *blackView;

@property (nonatomic, strong) UILabel *tipLabel;

@property (nonatomic, strong) UIImageView *stateImageView;

@property (nonatomic, strong) NSMutableArray *volumnImageArray;
@property (nonatomic, strong) UIImage *cancelImage;

@end

@implementation RecordView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.blackView = [[UIView alloc] initWithFrame:self.bounds];
        self.blackView.backgroundColor = [UIColor blackColor];
        self.blackView.alpha = 0.6f;
        self.blackView.layer.cornerRadius = 5;
        self.blackView.layer.masksToBounds = YES;
        [self addSubview:self.blackView];
        
        //显示的对应语音状态图片
        
        CGFloat width = CGRectGetWidth(frame);
        CGFloat height = CGRectGetHeight(frame);
        
        self.volumnImageArray = [NSMutableArray array];
        for (NSInteger i = 1; i < 7; i ++) {
            @autoreleasepool {
                NSString *imageName = [NSString stringWithFormat:@"chat_record_volumn%d", i];
                UIImage *volumnImage = [UIImage imageNamed:imageName];
                [self.volumnImageArray addObject:volumnImage];
            }
        }
        
        self.cancelImage = [UIImage imageNamed:@"chat_record_cancel"];
        
        self.stateImageView = [[UIImageView alloc] initWithFrame:CGRectMake((width - 117)/2, (height - 157)/2, 117, 117)];
        self.stateImageView.center = self.center;
        self.stateImageView.centerY -= 10;
        self.stateImageView.backgroundColor = [UIColor clearColor];
        [self addSubview:self.stateImageView];
        
        //显示的对应语音状态提示语
        self.tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, frame.size.height - 30, frame.size.width - 10, 20)];
        self.tipLabel.top = self.stateImageView.bottom;
        self.tipLabel.backgroundColor = [UIColor clearColor];
        self.tipLabel.font = [UIFont systemFontOfSize:15];
        self.tipLabel.textColor = [UIColor colorWithRed:193.0/255.0 green:193.0/255.0 blue:193.0/255.0 alpha:1];
        self.tipLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.tipLabel];
    }
    return self;
}

- (void)setVolumn:(NSUInteger)volumn
{
    if (volumn > 5) {
        volumn = 5;
    }
    
    self.stateImageView.image = [self.volumnImageArray objectAtIndex:volumn];
    self.stateImageView.size = self.stateImageView.image.size;
    self.tipLabel.text = @"手指上滑 取消发送";
}

- (void)showRecordCancel
{
    self.stateImageView.image = self.cancelImage;
    self.stateImageView.size = self.stateImageView.image.size;
    self.tipLabel.text = @"松开手指 取消发送";
}

@end
